package com.ulook.planetmanager.util;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.ulook.planetmanager.common.MyApplication;

/**
 * 描述：SharedPreferences工具类
 *
 * @author L1998
 * @data 2021/3/25
 */
public class SharedPreUtil {

    /**
     * 获取SharedPreferences.Editor对象
     * @param fileName
     * @return
     */
    public static SharedPreferences.Editor getEditor(String fileName){
        return MyApplication.getContext().getSharedPreferences(fileName, Context.MODE_PRIVATE).edit();
    }

    /**
     * 获取SharedPreferences对象
     * @param fileName
     * @return
     */
    public static SharedPreferences getSharedPre(String fileName){
        return MyApplication.getContext().getSharedPreferences(fileName, Context.MODE_PRIVATE);
    }

    /**
     * 获取SharedPreferences.Editor对象
     * @param fileName
     * @param application
     * @return
     */
    public static SharedPreferences.Editor getEditor(String fileName, Application application){
        return application.getApplicationContext().getSharedPreferences(fileName, Context.MODE_PRIVATE).edit();
    }

    /**
     * 获取SharedPreferences对象
     * @param fileName
     * @param application
     * @return
     */
    public static SharedPreferences getSharedPre(String fileName, Application application){
        return application.getApplicationContext().getSharedPreferences(fileName, Context.MODE_PRIVATE);
    }

    /**
     * 获取SharedPreferences.Editor对象
     * @param fileName
     * @param activity
     * @return
     */
    public static SharedPreferences.Editor getEditor(String fileName, Activity activity){
        return activity.getSharedPreferences(fileName, Context.MODE_PRIVATE).edit();
    }

    /**
     * 获取SharedPreferences对象
     * @param fileName
     * @param activity
     * @return
     */
    public static SharedPreferences getSharedPre(String fileName, Activity activity){
        return activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    }
}
